'use strict';
const constants = require('./contants');

exports.convertRestQueryParams = require('./rest-query').convertRestQueryParams;

exports.buildQuery = require('./rest-query').buildQuery;

exports.buildProjection = (include, exclude) => {
  if (Array.isArray(include) && Array.isArray(exclude)) {
    if (!include.length && !exclude.length) {
      return null;
    }

    const includeObj = {};
    const excludeObj = {};

    include.forEach(item => {
      includeObj[item] = 1;
    });
    exclude.forEach(item => {
      excludeObj[item] = 0;
    });

    return { ...includeObj, ...excludeObj };
  }

  return null;
};

exports.filterParams = (
  filters, payload) => Object.keys(payload)
  .forEach(key => filters.includes(key) && delete payload[key]);

exports.contants = constants;
